package com.cheyun.netsalev3.view.guide

import android.content.Intent
import androidx.fragment.app.Fragment
import androidx.viewpager.widget.ViewPager
import com.cheyun.netsalev3.R
import com.cheyun.netsalev3.adapter.HomePageAdapter
import com.cheyun.netsalev3.databinding.ActivityGuideBinding
import com.cheyun.netsalev3.utils.BaseActivity
import com.cheyun.netsalev3.utils.MySharedPreferences
import com.cheyun.netsalev3.utils.ScreenAdaptUtil
import com.cheyun.netsalev3.view.LoginActivity

class GuideActivity : BaseActivity<ActivityGuideBinding>() {
    override fun initContentView(): Int {
        return R.layout.activity_guide
    }

    override fun setStatusMode() {
        ScreenAdaptUtil.StatusBarLightMode(this)
    }

    var imgs = arrayOf(
            R.drawable.welcome_1,
            R.drawable.welcome_2,
            R.drawable.welcome_3,
            R.drawable.welcome_4
    )

    override fun initView() {
        var list = ArrayList<Fragment>()
        for (i in 0 until imgs.size) {
            list.add(GuideFragment.newInstance(i, imgs[i]))
        }
        binding.viewPager.adapter = HomePageAdapter(supportFragmentManager, list)

        binding.linearLayout.removeAllViews()
//        for (i in 0 until imgs.size) {
//            var chekbox = CheckBox(this)
//            chekbox.buttonDrawable = null
//            chekbox.background = ContextCompat.getDrawable(this, R.drawable.guide_yuan)
//            var layout = LinearLayout.LayoutParams(FunctionUtils.dip2px(this, 7f),
//                    FunctionUtils.dip2px(this, 7f))
//            if (i == 0) {
//                layout.leftMargin = FunctionUtils.dip2px(this, 0f)
//                chekbox.isChecked = true
//            } else {
//                layout.leftMargin = FunctionUtils.dip2px(this, 14f)
//                chekbox.isChecked = false
//            }
//            chekbox.layoutParams = layout
//            binding.linearLayout.addView(chekbox)
//        }

        binding.viewPager.addOnPageChangeListener(object : ViewPager.OnPageChangeListener {
            override fun onPageScrollStateChanged(state: Int) {

            }

            override fun onPageScrolled(position: Int, positionOffset: Float, positionOffsetPixels: Int) {
            }

            override fun onPageSelected(position: Int) {
//                for (i in 0 until binding.linearLayout.childCount) {
//                    var checkBox = binding.linearLayout.getChildAt(i) as CheckBox
//                    checkBox.isChecked = i == position
//                }
            }
        })
        binding.skipBut.setOnClickListener {
            startActivity(Intent(this, LoginActivity::class.java))
            finish()
        }
    }

    override fun initData() {
        MySharedPreferences.setGuide(false)
    }


}
